package com.cn.qtms.mq;//类注释设置模板

import com.cn.qtms.vo.SecKillVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Name:DelayOrderSender
 * @Description:
 * @Author: zhangyang
 * @Date: 2019-12-31 16:22
 **/
@Slf4j
@Component
public class DelayOrderSender {
    @Autowired
    private RabbitTemplate template;

    public void sendDelayMessage(SecKillVo vo){
        //模式是路由模式 使用delay_key 匹配交换机和队列
        template.convertAndSend("delay_exchange","delay_key",vo,message -> {
            //配置消息的过期时间
            message.getMessageProperties().setDelay(15000);
            return message;

        });
    }

    public void createOrder(SecKillVo vo){
        template.convertAndSend("order_queue", vo);
    }
}
